<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

//获取当前季节
//1.春季 2.夏季 3.秋季 4.冬季
function get_season()
{
    $month = date("m", time());
    $date = date("d", time());

    if ($month >= 1 && $month <= 3) $season = 4;
    if ($month == 3 && $date > 19) $season = 1;
    if ($month > 3 && $month <= 6) $season = 1;
    if ($month == 6 && $date > 20) $season = 2;
    if ($month > 6 && $month <= 9) $season = 2;
    if ($month == 9 && $date > 21) $season = 3;
    if ($month > 9 && $month <= 12) $season = 3;
    if ($month == 12 && $date > 20) $season = 4;
    
    return $season;
}
//虚拟用户名
function get_rand_name($name)
{
    $name = substr($name,0,1)."***".substr($name,5,3);
    return $name;
}
//密码混淆MD5
function pass_encode($password)
{
    $ci = &get_instance();
    $majorsalt = $ci->config->item('salt');
    // if PHP5
    if (function_exists('str_split'))
    {
        $_pass = str_split($password);
    }
    else
    {
        $_pass = array();
        if (is_string($password))
        {
            for ($i = 0; $i < strlen($password); $i++)
            {
                array_push($_pass, $password[$i]);
            }
        }
    }
    foreach ($_pass as $_hashpass)
    {
         $majorsalt .= md5($_hashpass);
    }
    return md5($majorsalt);
}
//查找数组
function _array_in_array($needle, $haystack) 
{
    if( ! is_array($needle)) 
    {
        $needle = array($needle);
    }
    foreach ($needle as $pin)
    {
        if (in_array($pin, $haystack)) 
            return TRUE;
    }
    return FALSE;
}
//发送邮件
function send_email($to, $subject, $message)
{
    $ci = &get_instance();
    $ci->load->library('Email');
    $ci->email->from($ci->config->item('site_email'));
    $ci->email->to($to);
    $ci->email->subject($subject);
    $ci->email->message($message);
    return $ci->email->send();
}
//图片服务器
function server_img($to)
{
    //$to = str_replace(base_url(),'/',$to);
    return 'http://img.ichufang.cn/'.$to;
}
//远程存图
//get_file("http://www.baidu.com/img/baidu_logo.gif","file","baidu.jpg"); 
function get_file($url,$pic_name)
{
    set_time_limit(24*60*60);                   //限制最大的执行时间  

    $destination_folder='./uploads/article/'.date("Ymd", time()).'/';    //文件下载保存目录  

    $newfname = $destination_folder.$pic_name;    //文件PATH  

    $file=fopen($url,'rb'); 

    if($file)
    {
        $newf=fopen($newfname,'wb');
        if($newf)
        {
            while(!feof($file))
            {
                fwrite($newf,fread($file,1024*8),1024*8);
            }
        }
        if($file)
        {
            fclose($file);
        } 
        if($newf)
        {
            fclose($newf);
        }
    }
}

/* End of file global_helper.php */
/* Location: ./system/helpers/global_helper.php */